<?php

class FormUsers extends App_Form  
{
	private $userData;
	
	public function __construct($user) {
		$this->userData = $user;
		parent::__construct();
	}
	/**
     * Создание формы
     */
    public function init()
    {
        parent::init();
        
        $helperUrl = new Zend_View_Helper_Url();
        $this->setAction($helperUrl->url(array(), 'adminUserForm'));
        $this->setMethod('post');
        $this->setAttrib('class', 'commonform');
        $this->setAttrib('name', 'userform');
        
        $id = new Zend_Form_Element_Hidden('hidden', array(
        	'name'		  => 'id',
            'value'       => $this->userData->id 
        ));
        $id->setDecorators(array('Hidden'));
        $this->addElement($id);

        $name = new Zend_Form_Element_Text('name', array(
            'required'    => true,
        	'label'       => 'Ф.И.О.',
            'maxlength'   => '30',
            'validators'  => array(
                array('Alnum', true, array(true)),
                array('StringLength', true, array(2, 100))
             ),
            'filters'     => array('StringTrim'),
            'value'		  => $this->userData->name
        ));
        $name->setDecorators(array('Standart'));
        $this->addElement($name);
        
        $login = new Zend_Form_Element_Text('login', array(
            'required'    => true,
        	'label'       => 'Логин',
            'maxlength'   => '30',
            'validators'  => array(
                array('Alnum', true, array(true)),
                array('StringLength', true, array(2, 30))
             ),
            'filters'     => array('StringTrim'),
            'value'		  => $this->userData->login
        ));
        $login->setDecorators(array('Standart'));
        $this->addElement($login);
        
        $passwd = new Zend_Form_Element_Text('passwd', array(
            'required'    => true,
        	'label'       => 'Пароль',
            'filters'     => array('StringTrim'),
            'value'		  => $this->userData->passwd
        ));
        $passwd->setDecorators(array('Standart'));
        $this->addElement($passwd);
      
        $blocked = new Zend_Form_Element_Checkbox('blocked', array(
			'decorators'=> $this->elementDecorators,
        	'label'     => 'Блокирован',
            'filters'   => array('StringTrim'),
            'value'		=> 1
        ));
        $blocked->setDecorators(array('Standart'));
        $blocked->setChecked($this->userData->blocked);
        $this->addElement($blocked);
        
		$submit = new Zend_Form_Element_Submit('submit', array(
			'decorators' => $this->buttonDecorators,
			'label'       => 'Сохранить',
		));
		$this->addElement($submit);
		        
		// Кнопка Reset, возвращает форму в начальное состояние
		$reset = new Zend_Form_Element_Reset('reset', array(
			'decorators' => $this->buttonDecorators,
			'label'       => 'Очистить',
		));
		$this->addElement($reset);
    }
}
?>
